﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using AnOtherBlog.Core;

namespace AnOtherBlog.AJAX.Admin.Users
{
	public partial class RoleList : AnOtherBlog.Core.Web.AdminBasePage
	{
		#region Constants

		private const string REDIRECT_PAGE = "~/Admin/Users/RoleList.aspx";

		#endregion

		#region Page Events

		/// <summary>
		/// Handles the Load event of the Page control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		protected void Page_Load(object sender, EventArgs e)
		{
			//base.LblMsg = this.lblMsg;
			try
			{
				string[] roles = Roles.GetAllRoles();
				dgRoles.DataSource = roles;
				dgRoles.DataBind();
				Page.Title = Resources.AdminUsers.lblApplication + Resources.AdminUsers.lblRoleAdministration;
			}
			catch (Exception ex)
			{
				MsgSetCritical(ex.Message);
			}
		}

		/// <summary>
		/// Handles the Click event of the lbDelete control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param>
		protected void lbDelete_Click(object sender, CommandEventArgs e)
		{
			try
			{
				if (e.CommandName.Equals("mydelete"))
				{
					string roleName = e.CommandArgument as string;
					//Roles.DeleteRole(roleName);
					//Response.Redirect(REDIRECT_PAGE);
					MsgSet("Se debería borrar el rol " + roleName);
				}
			}
			catch (Exception ex)
			{
				MsgSetCritical(ex.Message);
			}
		}

		/// <summary>
		/// Handles the Click event of the btnSave control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		protected void btnSave_Click(object sender, EventArgs e)
		{
			if (Page.IsValid)
			{
				try
				{
					Roles.CreateRole(txtRoleName.Text.Trim());
					Response.Redirect(REDIRECT_PAGE);
				}
				catch (Exception ex)
				{
					MsgSetCritical(ex.Message);
				}
			}
		}

		#endregion

	}
}
